/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mvp.algorithms.main;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import mvp.algorithms.unions.QuickFind;
import mvp.algorithms.unions.QuickUnionChecker;
import mvp.algorithms.unions.WeightedQuickUnion;

/**
 * @author WORKSPOT2
 */
public class Algorithms {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        log2(3.52d, 3.53d);

    }

    private static void log2(double... nums) {
        for (int i = 0; i < nums.length; i++) {
            double res = (Math.log(nums[i]) / Math.log(2));
            System.out.println(nums[i] + " : " + res);
        }
    }

    private static void testAlg() {
        for (int n = 100; n < 110; n++) {
            int sum = 0;
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j += i)
                    sum++;
            System.out.println("N:" + n + " - " + sum);
            calcFunctions(n);
            System.out.println("-----------------------");
        }
    }

    private static void calcFunctions(double n) {
        System.out.println("N^1/2: " + Math.pow(n, 0.5d));
        System.out.println("log N: " + logn(n));
        System.out.println("Nlog N: " + nlogn(n));
        System.out.println("N^(3/2): " + Math.pow(n, 1.5d));
//        System.out.println("N^2: " + Math.pow(n, 2.0d));
//        System.out.println("N^2 log N: " + n2logn(n));
//        System.out.println("N^(5/2): " + Math.pow(n, 2.5d));
//        System.out.println("N^3: " + Math.pow(n, 3.0d));
//        System.out.println("N^4: " + Math.pow(n, 4.0d));
//        System.out.println("N^5: " + Math.pow(n, 5.0d));
//        System.out.println("N^6: " + Math.pow(n, 6.0d));
//        System.out.println("N^7: " + Math.pow(n, 7.0d));
    }

    private static double n2logn(double n) {
        return Math.pow(n, 2) * logn(n);
    }

    private static double nlogn(double n) {
        return n * logn(n);
    }

    private static double logn(double n) {
        return (Math.log(n) / Math.log(2));
    }

    private static void quicFindTask() {
//         6-2 3-8 9-5 0-9 1-0 5-8
        QuickFind qf = new QuickFind(10);
        qf.union(6, 2);
        qf.union(3, 8);
        qf.union(9, 5);
        qf.union(0, 9);
        qf.union(1, 0);
        qf.union(5, 8);
        qf.printIdArray();
    }

    private static void weightedQuickFindTask() {
        //5-4 0-9 8-2 8-3 7-1 9-5 7-3 0-2 8-6
        WeightedQuickUnion wqu = new WeightedQuickUnion(10);
        wqu.union(5, 4);
        wqu.union(0, 9);
        wqu.union(8, 2);
        wqu.union(8, 3);
        wqu.union(7, 1);
        wqu.union(9, 5);
        wqu.union(7, 3);
        wqu.union(0, 2);
        wqu.union(8, 6);
        wqu.printIdArray();
    }


    private static void findPossibleString() {
        List<String> variants = new ArrayList<String>();
        variants.add("2 2 8 2 7 2 9 2 8 2");
//        variants.add("0 8 3 3 7 1 5 3 0 1");
//        variants.add("6 9 4 7 3 4 4 6 9 4");
        variants.add("1 1 1 1 7 1 8 5 1 5");

        QuickUnionChecker quc = new QuickUnionChecker(10);
        Iterator<String> iter = variants.iterator();
        String tmp;
        boolean tmpCheck;
        while (iter.hasNext()) {
            tmp = iter.next();
            tmpCheck = quc.checkString(tmp);
            System.out.println(tmp + " - " + tmpCheck);
        }
    }
}
